/***************************************************************************
 创建者: 华磊
 开始时间: 2019.4.3
 copyright: (C) 华友高科
 修改说明:
 ***************************************************************************
 *  @file
 *  功能:
 * 伺服位置环
 *
 *                                                                         *
 ***************************************************************************/

#ifndef POSITIONREGULATOR_H
#define POSITIONREGULATOR_H
#include "pid_controller.h"
#include "mathonlydefine.h"
#include "GeneralDefine.h"
class FilteringAlgorithm;
//todo 对于反馈位置可能因为ｄｃ的问题，导致偶尔有延迟，是否需要做滤波处理？
class PositionRegulator
{
public:
    PositionRegulator(int axisIdIn,double deltaTimeIn, RegulatorConfigInfo configInfoIn, E_REGULATOR_TYPE typeIn);

public:
    int getPositionRegulatorDebugInfo(RegulatorDebugInfo& infoOut);
    bool isValid( );
    int setServoStatus(bool isServoOn);
    int setPositionPid(double pid_p, double pid_i, double pid_d, double errorLimitForIntegration, double feedforward);
    int setPositionInput(double positionInput);
    int loopRegulatorOnce(double targetPositionIn, double feedbackPositionIn, double &velOutut);
    int loopRegulatorOnce(double feedbackPositionIn, double &velOutut);
    int quickStop();
    int stop();
    int cease();
    int resetAll();
    int startRun();
    bool isInitialOk();

private:
    PIDControl *pidController;

    double targetPosition;
    double feedbackPosition;
    double velCommand;

    int axisId;
    double deltaTime;
    RegulatorConfigInfo configInfo;
    E_REGULATOR_STATUS status;
    E_REGULATOR_TYPE regulatorType;
    FilteringAlgorithm *filter;

};

#endif // POSITIONREGULATOR_H
